/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.anniversary.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.sql.Timestamp;

/**
* @website https://el-admin.vip
* @description /
* @author Jiayin Wei
* @date 2020-07-28
**/

@Getter
@Setter
@EntityListeners(AuditingEntityListener.class)
@Entity
@Data
@Table(name="v_teacher_student_info")
public class SelectUser implements Serializable {

    @Id
    @Column(name = "id")
    @ApiModelProperty(value = "编号ID")
    private Long id;

    @Column(name = "user_id")
    @NotBlank
    @ApiModelProperty(value = "用户ID")
    private Long userId;

    @Column(name = "user_type")
    @NotBlank
    @ApiModelProperty(value = "用户类型")
    private Long userType;

    @Column(name = "name")
    @NotBlank
    @ApiModelProperty(value = "名称")
    private String name;

    @Column(name = "gender")
    @ApiModelProperty(value = "性别")
    private String gender;

    @Column(name = "birth_date")
    @ApiModelProperty(value = "出生年月")
    private String birthDate;

    @Column(name = "nation_id")
    @ApiModelProperty(value = "民族ID")
    private Long nationId;

    @Column(name = "political_id")
    @ApiModelProperty(value = "政治面貌ID")
    private Long politicalId;

    @Column(name = "phone")
    @ApiModelProperty(value = "联系电话")
    private String phone;

    @Column(name = "joined")
    @ApiModelProperty(value = "是否加入")
    private Long joined;

    public void copy(SelectUser source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }

    @Override
    public String toString() {
        ToStringBuilder builder = new ToStringBuilder(this);
        Field[] fields = this.getClass().getDeclaredFields();
        try {
            for (Field f : fields) {
                f.setAccessible(true);
                builder.append(f.getName(), f.get(this)).append("\n");
            }
        } catch (Exception e) {
            builder.append("toString builder encounter an error");
        }
        return builder.toString();
    }
}
